package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.web.admin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author = 赵子涵
 * @date = 2025/4/30 17:04
 * @function =
 */
@RestController
@RequestMapping("/admin/term")
public class LeaseTermController {
    @Autowired
    LeaseTermService leaseTermService;
    @GetMapping("/list")
    @Operation(summary = "查询全部租期列表")
    public Result listAll() {
        List<LeaseTerm> list = leaseTermService.list();
        return Result.ok(list);
    }
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "保存或更新租期信息")
    public Result saveOrUpdate(@RequestBody LeaseTerm leaseTerm) {
        boolean save = leaseTermService.saveOrUpdate(leaseTerm);
        return save ? Result.ok() : Result.fail(ResultCodeEnum.FAIL.getCode(),ResultCodeEnum.FAIL.getMessage());
    }
    @DeleteMapping("/deleteById")
    @Operation(summary = "根据ID删除租期")
    public Result deleteById(@RequestParam Long id){
        boolean delete = leaseTermService.removeById(id);
        return delete ? Result.ok() : Result.fail(ResultCodeEnum.FAIL.getCode(),ResultCodeEnum.FAIL.getMessage());
    }
}
